from flask import Flask, request
from hyper import HTTP20Connection
from hyper.contrib import HTTP20Adapter
from hyper.tls import init_context
from werkzeug.serving import run_simple

app = Flask(__name__)


@app.route('/', methods=['GET'])
def home():
    return 'Hello, HTTP/2!'


def create_server():
    context = init_context()
    context.check_hostname = False
    context.verify_mode = context.CERT_NONE

    def quic_server(environ, start_response):
        return app(environ, start_response)

    server = run_simple(
        'localhost',
        443,
        quic_server,
        transport=HTTP20_QUIC_TRANSPORT,
        quic=True,
        h2=True,
        ssl_context=context,
        h2_settings=H2_SETTINGS,
    )
    return server


if __name__ == '__main__':
    create_server()